home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 1541 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.6 KB  |  69 lines

  1. Newsgroups: comp.lang.c++
  2. Path: artemis.sto.fdata.se!news
  3. From: Niklas Mellin <niklas.mellin@sto.fdata.se>
  4. Subject: Re: Is this code valid?
  5. Sender: news@artemis.sto.fdata.se (UseNet NetNews)
  6. Message-ID: <30F531DB.D8A@sto.fdata.se>
  7. Date: Thu, 11 Jan 1996 15:50:51 GMT
  8. Content-Transfer-Encoding: 7bit
  9. Content-Type: text/plain; charset=us-ascii
  10. References: <30F3E42D.74BA@sto.fdata.se> <30F43E85.7C9B@bangate.compaq.com>
  11. Mime-Version: 1.0
  12. X-Mailer: Mozilla 2.0b4 (WinNT; I)
  13. Organization: WM-data F÷rsvarsdata AB, Sweden
  14.  
  15. Saurabh Dixit wrote:
  16. > Niklas Mellin wrote:
  17. > >
  18. > > class X
  19. > > {
  20. > >   public:
  21. > >   class Y;
  22. > > };
  23. > >
  24. > > class X::Y
  25. > > {
  26. > > };
  27. > >
  28. > > int main(int, char* [])
  29. > > {
  30. > >   throw X::Y();
  31. > >   return 0;
  32. > > }
  33. > >
  34. > > It doesn't matter if the throw statement is in main or in
  35. > > some other function, and it makes no difference if there 
  36. > > is a catch statement.
  37. > >
  38. > > When linking the code above in Borland C++ 4.0 the ide
  39. > > crashes killing windows too (it took me a while to 
  40. > > isolate the problem).
  41. > >
  42. > > Borland 4.5 doesn't crash but reports: "Internal error..."
  43. > > some number.
  44. > >
  45. > > My question: Is it allowed to throw objects of nested
  46. > > classes?
  47. > >
  48. > > ---
  49. > > Niklas Mellin
  50. > Though I wouldn't expect a compiler to crash when it
  51. > encounters possible bad code, I don't see what you are
  52. > trying to throw.
  53. > Don't you need an object to throw?
  54.  
  55. Yes.
  56.  
  57. > In the statement
  58. > throw X::Y() where is the object?
  59.  
  60. Right in front of you. X::Y() is the default constructor
  61. of Y, so a temporary object of that class is created, and
  62. it is that temporary that is thrown. I believe this is a 
  63. standard technique.
  64.  
  65. ---
  66. Niklas Mellin
  67.